﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading
Imports System.Threading.Tasks

Namespace vindinium
	Friend Class RandomBot
		Private serverStuff As ServerStuff

		Public Sub New(ByVal serverStuff As ServerStuff)
			Me.serverStuff = serverStuff
		End Sub

		'starts everything
		Public Sub run()
			Console.Out.WriteLine("random bot running")

			serverStuff.createGame()

			If serverStuff.errored = False Then
				'opens up a webpage so you can view the game, doing it async so we dont time out
				CType(New Thread(Sub() System.Diagnostics.Process.Start(serverStuff.viewURL)), Thread).Start()
			End If

			Dim random As New Random()
			Do While serverStuff.finished = False AndAlso serverStuff.errored = False
				Select Case random.Next(0, 6)
					Case 0
						serverStuff.moveHero(Direction.East)
					Case 1
						serverStuff.moveHero(Direction.North)
					Case 2
						serverStuff.moveHero(Direction.South)
					Case 3
						serverStuff.moveHero(Direction.Stay)
					Case 4
						serverStuff.moveHero(Direction.West)
				End Select

				Console.Out.WriteLine("completed turn " & serverStuff.currentTurn)
			Loop

			If serverStuff.errored Then
				Console.Out.WriteLine("error: " & serverStuff.errorText)
			End If

			Console.Out.WriteLine("random bot finished")
		End Sub
	End Class
End Namespace
